using UnityEngine;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using HWGames.Bundles.Internal.Editor;

namespace HWGames.Bundles.Internal.Analytics.Editor {
    public class SingularPreBuild : IPreprocessBuildWithReport {
        public int callbackOrder => 1;

        public void OnPreprocessBuild(BuildReport report) {
            CheckAndUpdateSettings(SDKBundleSettings.Load());
        }

        public static void CheckAndUpdateSettings(SDKBundleSettings settings) {
#if UNITY_ANDROID || UNITY_IOS
            if (settings == null || string.IsNullOrEmpty(settings.SingularAPIkey)|| string.IsNullOrEmpty(settings.SingularSecretkey))
                BuildErrorWindow.LogBuildError(BuildErrorConfig.ErrorID.SettingsNoSingularID);
#endif
        }
    }
}